package com.ants.boot.system.controller;

import com.ants.boot.core.Response;
import com.ants.boot.core.annotation.Log;
import com.ants.boot.model.BaseController;
import com.ants.boot.system.domain.SysLoginLog;
import com.ants.boot.system.dto.sysloginlog.DelSysLoginLogDto;
import com.ants.boot.system.dto.sysloginlog.QuerySysLoginLogDto;
import com.ants.boot.system.service.SysLoginLogService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 蚂蚁会花呗
 * @date 2022/3/21 15:59
 */
@RestController
@RequestMapping("system/sys_login_log")
@Api(tags = "登录日志")
public class SysLoginLogController extends BaseController {

    @Autowired
    private SysLoginLogService sysLoginLogService;

    /**
     * 日志分页
     * @param dto
     * @return
     */
    @PostMapping("page_info")
    @Log(module = "登录管理",operate = "查询、搜索")
    @ApiOperation(value = "登录分页",notes = "登录查询搜索")
    public Response pageInfo(@RequestBody @Validated QuerySysLoginLogDto dto){
        IPage<SysLoginLog> iPage = sysLoginLogService.pageInfo(dto);
        return Response.okData(iPage);
    }

    /**
     * 删除和批量删除
     * @param dto
     * @return
     */
    @PostMapping("del_sys_login_log")
    @Log(module = "登录管理",operate = "删除登录日志")
    @ApiOperation(value = "删除登录日志",notes = "删除登录日志")
    public Response delSysLoginLog(@RequestBody @Validated DelSysLoginLogDto dto){
        boolean result = sysLoginLogService.delSysLoginLog(dto.getIds());
        if (!result){
            return Response.fail();
        }
        return Response.ok();
    }

}
